<?php

if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Frameworkmodel extends CI_Model {

	protected $_CI;

	public static $searchField = array();
	public static $likeField = array();

	public function __construct(){
		parent::__construct();
		$this->_CI = & get_instance();
	}
/*
| -------------------------------------------------------------------
|  GET Functions
| -------------------------------------------------------------------
*/
	public function getFrameworkFileList($assist){
		$this->db->from('framework_file');
		if(!empty($assist['where'])) $this->db->where($assist['where']);
		if(!empty($assist['like'])) $this->db->like($assist['like']);
		$this->db->order_by('framework_file_sort','desc');
		$this->db->order_by('framework_file_id','asc');
		$query = $this->db->get();
		$list = $query->result_array();

		return $list;
	}

	public function getFrameworkFile($framework_file_id){
		$this->db->from('framework_file');
		$this->db->where('framework_file_id',$framework_file_id);
		$this->db->limit(1);
		$query = $this->db->get();
		$item = $query->row_array();

		return $item;
	}

	public function getFrameworkCss(){
		$this->db->select('framework_file_content');
		$this->db->from('framework_file');
		$this->db->where('framework_file_status',STATUS_ACTIVE);
		$this->db->order_by('framework_file_sort','desc');
		$this->db->order_by('framework_file_id','asc');
		$query = $this->db->get();
		$list = $query->result_array();

		$content = extractColumn($list,'framework_file_content');
		$content = implode(' ',$content);

		return $content;
	}
/*
| -------------------------------------------------------------------
|  CREATE Functions
| -------------------------------------------------------------------
*/
	public function createFrameworkFile($info){
		$this->db->insert('framework_file',$info);
		return $this->db->insert_id();
	}
/*
| -------------------------------------------------------------------
|  EDIT Functions
| -------------------------------------------------------------------
*/
	public function editFrameworkFile($framework_file_id,$info){
		$this->db->where('framework_file_id',$framework_file_id);
		$this->db->update('framework_file',$info);
	}

	public function editFrameworkFiles($info){
		if(!empty($info)){
			$this->db->update_batch('framework_file',$info,'framework_file_id');
		}
	}
/*
| -------------------------------------------------------------------
|  DELETE Functions
| -------------------------------------------------------------------
*/
/*
| -------------------------------------------------------------------
|  CHECK Functions
| -------------------------------------------------------------------
*/
	public function checkNameAvailable($name,$framework_file_id = 0){
		$this->db->from('framework_file');
		$this->db->where('framework_file_id !=',$framework_file_id);
		$this->db->where('framework_file_name',$name);
		$count = $this->db->count_all_results();

		return ($count == 0);
	}
/*
| -------------------------------------------------------------------
|  INIT Functions
| -------------------------------------------------------------------
*/
/*
| -------------------------------------------------------------------
|  OUTPUT Functions
| -------------------------------------------------------------------
*/
}